package hd.cls9;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class ChatClient {
    public static void main(String[] args) {
        try {
            Socket s = new Socket("localhost", 9999);
            InputStream in = s.getInputStream();//网络流
            OutputStream out = s.getOutputStream();
            PrintWriter pw = new PrintWriter(out, true);//
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
            //客户端的输入对应服务器的输出
            Scanner input = new Scanner(System.in);
            while (true) {
                System.out.println("唠嗑:");
                String msg = input.next();
                pw.println(msg);
                String reply = br.readLine();
                System.out.println("服务器回复说：" + reply);
                if (msg.equals("byebye")) {
                    break;
                }
            }
            System.out.println(s + "被关闭了");
            s.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
